package com.csweimei.rentmanagementtreasure.tenant.viewModel;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;

import androidx.annotation.NonNull;
import androidx.databinding.ObservableField;

import com.csweimei.rentmanagementtreasure.base.AppConfig;
import com.csweimei.rentmanagementtreasure.http.entity.HouseListBean;
import com.csweimei.rentmanagementtreasure.pop.PopEditHouse;
import com.csweimei.rentmanagementtreasure.pop.PopUtils;
import com.csweimei.rentmanagementtreasure.tenant.ui.act.house.HouseDetailHzActivity;
import com.csweimei.rentmanagementtreasure.tenant.ui.act.house.HouseDetailZzActivity;

import me.goldze.mvvmhabit.base.BaseViewModel;
import me.goldze.mvvmhabit.base.MultiItemViewModel;
import me.goldze.mvvmhabit.binding.command.BindingAction;
import me.goldze.mvvmhabit.binding.command.BindingCommand;

public class HouseInfoCVM extends MultiItemViewModel {
    public ObservableField<HouseListBean.DataDTO.ArrDTO> bean = new ObservableField<>();

    HouseInfoVM houseInfoVM;
    public ObservableField<Integer> showEdit = new ObservableField<>(View.VISIBLE);
    public ObservableField<Integer> showChoose = new ObservableField<>(View.GONE);

    public HouseInfoCVM(@NonNull BaseViewModel viewModel, HouseListBean.DataDTO.ArrDTO cBean) {
        super(viewModel);
        bean.set(cBean);
        houseInfoVM = (HouseInfoVM) viewModel;

        if (houseInfoVM.flag.get().equals("choose")){
            showChoose.set(View.VISIBLE);
            showEdit.set(View.GONE);
        }else {
            showChoose.set(View.GONE);
            showEdit.set(View.GONE);
        }
    }

    public BindingCommand itemClick = new BindingCommand(new BindingAction() {
        @Override
        public void call() {
            if (houseInfoVM.flag.get().equals("choose")){
                Intent intent = new Intent();
                intent.putExtra("data",bean.get());
                houseInfoVM.mActivity.setResult(10087,intent);
                houseInfoVM.finish();
            }else {
                if (houseInfoVM.selType.get().equals("整租")){
                    Bundle bundle = new Bundle();
                    bundle.putInt(AppConfig.BUNDLE_KEY,bean.get().getId());
                    bundle.putString(AppConfig.BUNDLE_KEY2,"person");
                    viewModel.startActivity(HouseDetailZzActivity.class,bundle);
                }else {
                    Bundle bundle = new Bundle();
                    bundle.putInt(AppConfig.BUNDLE_KEY,bean.get().getId());
                    bundle.putString(AppConfig.BUNDLE_KEY2,"person");
                    viewModel.startActivity(HouseDetailHzActivity.class,bundle);
                }

            }
        }
    });


    public BindingCommand editClick = new BindingCommand(new BindingAction() {
        @Override
        public void call() {
            PopEditHouse popEditHouse = new PopEditHouse(viewModel.mActivity);
            popEditHouse.setSelBack(x -> {
                String status;
                switch (x.getName()){
                    case "签约中":
                        status = "1";
                        break;
                    case "不可用":
                        status = "2";
                        break;
                    default:
                        status = "0";
                        break;

                }
                houseInfoVM.setHouseStatus(bean.get().getId(),status);
            });
            popEditHouse.setSelId(bean.get().getId());
            popEditHouse.setSelType(houseInfoVM.selType.get());
            PopUtils.showPop(viewModel.mActivity, popEditHouse,false);
        }
    });

}
